<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
       <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title><spring:message code="company_account_createBankAccount"/></title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   
     <script type="text/javascript">
    
 
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	
   		$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
    			createAccount();
          	}
     	});
	});
    
function createAccount(){
	//获取 iframe 数量 
   	var frLength = window.parent.frames.length;
   	//父画面下标 
   	var parentIndex = frLength-2;
	var imageFlg = $("#imageFlg").val();
	var index = $("#index").val();
	var frameObj = window.parent.frames[parentIndex].document.getElementById("perantTable");
	/* 删除该行  */
	if (index!=null && index!="" && index!=0) {
		$(frameObj)[0].rows[index].remove();
	}
	/* 追加新的一行 */
	var name = $("#name").val();
	var instructions = $("#instructions").val();
	var state = $("input:radio:checked").val();
	var yesOrNo ;
	if (state==1) {
		yesOrNo = "<spring:message code="company_account_defaultAccount"/>";
	}else{
		yesOrNo = "<spring:message code="company_account_notDefaultAccount"/>";
	}
	$("#state").val(state);
	var createTime = $("#createTime").val().toString();
	var jbren = $("#jbren").val().toString();
	var jbrenName = $("#jbrenName").val();
	var ognizationName = $("#ognizationName").val();
	var brandName = $("#brandName").val();
	// 画面区分
	if (imageFlg == "fashionStyleCreate") {
        if (confirm('<spring:message code="process_Special_YorN"/>')==true){

            var nameImage = $("#nameImage").val();
            var urlTemp = '';
            var nameTemp='';

            if (nameImage!='') {
            var fileTemp = nameImage.split("|")[1].split("/");
            var lenTemp = fileTemp.length-1;
             	nameTemp=fileTemp[lenTemp];
                for (var j = 1; j < lenTemp; j++) {
                    urlTemp += fileTemp[j] + "/";
                }
            }
			$("#filePath").val("/"+urlTemp);
            $("#uploadFile").val(nameTemp);
            var params = $("#inputForm").serialize();
            $.post("${ctx}/produce/technology/saveProcess",params,function(result){
				var saveFlg = result["saveFlg"];
                var proId = result["proId"];
                if (saveFlg == "true") {
                    var tbodyTemp = window.parent.frames[parentIndex].document.getElementById("productionTable");
                    var lenTr = $(tbodyTemp).find("tr").length-1;
                    var tempData = $(tbodyTemp).find("tr").eq(0).clone();
                    var tempDataCells=$(tempData)[0].cells;
                    tempDataCells[1].innerHTML = '<spring:message code="special_pro"/>';
                    var imageUrl="";
                    if (nameImage!="") {
                        imageUrl = nameImage.split("|")[1];
					} else {
                        imageUrl = '${ctxStatic}/images/pic-none.jpg';
					}
                    tempDataCells[2].innerHTML = '<img src="'+imageUrl+'" style="width:100px">';
                    tempDataCells[3].innerHTML = instructions;
                    tempDataCells[6].innerHTML = $("#jbrenName").val();
                    tempDataCells[7].innerHTML = createTime;
                    tempDataCells[8].innerHTML = '<input type="hidden" name="productionEntity.productionList[tempIndex].craftId" value="'+proId+'">';
                    $(tempData)[0].className="";
                    tempData.appendTo(tbodyTemp);
                    closeWin();
				}
            },'json');
        }else{
            return false;
        }
	} else {
		var len = $(frameObj).find("tr").length;
		//var nameImagePath = $("#nameImage").val().replace("|","");		
		/* var nameHidden = "<input type='hidden' name='processList["+(len-1)+"].name' value='"+name+"'/>";
		var processFileHidden = "<input type='hidden' name='processList["+(len-1)+"].nameImagePath' value='"+nameImagePath+"'/>";
		var instructionsHidden = "<input type='hidden' name='processList["+(len-1)+"].instructions' value='"+instructions+"'/>";
		var stateHidden = "<input type='hidden' name='processList["+(len-1)+"].state' value='"+state+"'/>";
		var jbrenHidden = "<input type='hidden' name='processList["+(len-1)+"].jbren' value='"+jbren+"'/>";
		var createTimeHidden = "<input type='hidden' name='processList["+(len-1)+"].createTime' value='"+createTime+"'/>";	
		
		var hiddenData = nameHidden+processFileHidden+instructionsHidden+stateHidden+jbrenHidden+createTimeHidden */
		var nameImage = $("#nameImage").val();
        var urlTemp = '';
        var nameTemp='';

        if (nameImage!='') {
        var fileTemp = nameImage.split("|")[1].split("/");
        var lenTemp = fileTemp.length-1;
         	nameTemp=fileTemp[lenTemp];
            for (var j = 1; j < lenTemp; j++) {
                urlTemp += fileTemp[j] + "/";
            }
        }
		$("#filePath").val("/"+urlTemp);
        $("#uploadFile").val(nameTemp);
        var params = $("#inputForm").serialize();
        $.post("${ctx}/produce/technology/saveProcess",params,function(result){
        	var saveFlg = result["saveFlg"];
        	var processId = result["processId"];
        	if (saveFlg == "true") {
        		tipParent("保存成功");
            	var tempData = $(frameObj).find("tr").eq(0).clone();
         		var tempDataCells=$(tempData)[0].cells;
         		var imageUrl="";
                if (nameImage!="") {
                    imageUrl = nameImage.split("|")[1];
				} else {
                    imageUrl = '${ctxStatic}/images/pic-none.jpg';
				}
                var popup = "popupEdit(this,'id="+processId+"&name="+name+"&nameImagePath="+imageUrl+"&instructions="+instructions+"&state="+state+"')";
                tempDataCells[0].innerHTML='<img src="${ctxStatic}/images/btn-bj.png" onclick="'+popup+'" height="30" width="30">&nbsp;&nbsp;<img src="${ctxStatic}/images/btn-sc.png" height="30" width="30"  onclick="deleteCurrentRow(this,'+processId+');">';
         		tempDataCells[1].innerText=name; 
         		tempDataCells[2].innerHTML='<img src="'+imageUrl+'" style="width:40px">';
         		tempDataCells[3].innerHTML=ognizationName
         		tempDataCells[4].innerHTML=brandName;
         		tempDataCells[5].innerText=instructions;
         		if (state=="1") {
         			state="启用";
				}else{
					state="停用";
				}
         		tempDataCells[6].innerText=state;
         		tempDataCells[7].innerText=jbrenName;
         		tempDataCells[8].innerText=createTime;
         		//tempDataCells[9].innerHTML=hiddenData;
         		$(tempData)[0].className="";
         		/* $(tempData).find("div").innerHTML = hiddenData; */
         		tempData.appendTo(frameObj);
                closeWin()
        	}
        },'json');
	}
}
    </script> 
</head>
<body>
<!-- 创建页面head部 -->
<form id="inputForm">
	<div class="layerHeader clearfix">
		<c:choose>
	        <c:when test="${process.index!=null && process.index!='' && process.index!=0}">
	             <!-- 修改编辑 -->
	            <p class="headerTitle"><spring:message code="dict_modifyDict"/></p>
	        </c:when>
			<c:when test="${process.imageFlg=='fashionStyleCreate'}">
				<!-- 新建特殊工艺 -->
				<p class="headerTitle"><spring:message code="create_pross_special"/></p>
			</c:when>
	        <c:otherwise>
	             <!-- 新建 -->
	            <p class="headerTitle"><spring:message code="dict_createDict"/></p>
	        </c:otherwise>
	    </c:choose>
	    <div class="headerButton clearfix">
	     <c:choose>
    		<c:when test="${process.index!=null && process.index!='' && process.index!=0 }">
    		<button type="button" id="okButton"><spring:message code="company_account_save"/></button>
    		</c:when>
      	<c:otherwise>
      		<button type="button" id="okButton"><spring:message code="company_account_create"/></button>
      	</c:otherwise>  
    	</c:choose>
        <button type="button" onclick="closeWin()"><spring:message code="company_account_cancle"/></button>	    
	       
	    </div>
	</div>




  <div class="tabBoxSm">
   <div class="tabSm smOrderBox">
   	   <input type="hidden" id="id" name="id" value="${process.id}">
	   <input type="hidden" id="index" name="index" value="${process.index}">
	   <input type="hidden" id="jbren" name="jbren" value="${fns:getUser()}">
	   <input type="hidden" id="jbrenName" value="${user}">
	   <input type="hidden" id="createTime" name="createTime" value="${fns:getDate('yyyy-MM-dd')}">
	   <input type="hidden" id="imageFlg" name="imageFlg" value="${process.imageFlg}"/>
	   <input type="hidden" name="category" value="${process.category}"/>
	   <input type="hidden" name="procategory" value="${process.procategory}">
	   <input type="hidden" id="brandId" name="brandId" value="${process.brandId}"/>
	   <input type="hidden" id="venderId" name ="venderId" value="${process.venderId}">
	   <input type="hidden" id="brandName" name="brandName" value="${process.brandName}"/>
	   <input type="hidden" id="ognizationName" name ="ognizationName" value="${process.ognizationName}">
	   <input type="hidden" id="state" value="${process.state}">

	   <input type="hidden" name="uploadFileData.moduleKbn" value="2">
	   <input type="hidden" name="uploadFileData.fileKbn" value="0">
	   <input type="hidden" name="uploadFileData.ftpFile" value="/process">
	   <input type="hidden" id="filePath" name="uploadFileData.filePath" value="">
	   <input type="hidden" id="uploadFile" name="uploadFileData.uploadFile" value="">
	   <input type="hidden" name="uploadFileData.fileSource" value="1">
	   <input type="hidden" name="uploadFileData.createUser" value="${fns:getUser()}">
	   <input type="hidden" name="uploadFileData.createTime" value="${fns:getDate('yyyy-MM-dd hh:ss')}">
       <div class="clearfix">
	     <div class="left" style="width: 50%;">
        		<!-- 名称 -->
	            <div class="items clearfix haveToBox">
            		<p class="tit"><spring:message code="production_process_name"/></p>
          			<input id="name" name="name" value="${process.name}" style="width: 200px" data-rule-required="true" data-msg-required="<spring:message code="dict_pleaseInputItemCn"/>">
        		</div>
        		<!-- 说明  -->
        		<div class="items clearfix haveToBox">
            		<p class="tit"><spring:message code="production_process_instructions"/></p>            	
            		<textarea id="instructions" name="instructions" style="width: 350px;height:220px;" data-rule-required="true" data-msg-required="<spring:message code="production_process__pleaseInputInstructions"/>">${process.instructions}</textarea>
        		</div>
        		<!-- 状态  -->
        		<div class="items clearfix haveToBox">
        		<p class="tit"><spring:message code="dict_state" /></p>
            		<div class="labelBox">
						<!--启用-->
						<label> <input type="radio" name="state"
							checked='checked' value="1"
							<c:if test="${process.state eq 1}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_enable" /> 
						</label>
						<!--停用-->
						<label><input type="radio" name="state" value="0"
							<c:if test="${process.state eq 0}">checked="checked"</c:if>
							class="rast" /> <spring:message code="dict_disable" /> 
						</label>
					</div>         			
                </div>
        		<!-- 创建人  -->
        		<div class="items clearfix haveToBox">        			
            		<p class="tit"><spring:message code="production_process_founder"/></p>
					<label>${user}</label>
					<input type="hidden" id ="createUser" value="${user}"  disabled="disabled">
                </div>
        		<!-- 创建日期  -->
                <div class="items clearfix haveToBox">        			
            		<p class="tit"><spring:message code="production_process_create_date"/></p>
					<label>${fns:getDate('yyyy-MM-dd hh:ss')}</label>
                </div>                
	     </div>
	     <div class="right "style="width: 50%;">
        		<!-- 图片  -->
	            <div class="items clearfix haveToBox">
            		<p class="tit"><spring:message code="production_process_picture"/></p>               
                	<div class="styleImgBg clearfix" style="width: 310px; height: 300px; padding-top: 30px; margin-left: 25px; float: left;">							
							 <c:set value="" var="myStyleFileTemp" />
						       <%-- <c:forEach items="${myStyleFileList}" var="styleFile"> --%>
							   <c:set var="myStyleFileTemp"
							       value="${myStyleFileTemp}|${process.nameImagePath}" />
						       <%-- </c:forEach> --%>
						       <div class="square" style="width: 330px; height: 230px; margin-top: -1px; margin-left: -30px;">
							   <input type="hidden" id="nameImage" name="nameImagePath" value="${myStyleFileTemp}" htmlEscape="false" class="input-xlarge" />
							   <sys:ckfinder input="nameImage" type="images"  uploadPath="/process" selectMultiple="true" maxWidth="255" maxHeight="255" />
						       </div>														
					</div>           
        		</div>
	     </div>
	   </div>  
    </div>
  </div>

</form>		
</body>
</html>